/*
 * File Name:               GameobjectPool.cs
 *
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/19
 */

using System.Collections.Generic;
using UnityEngine;

public class XObjectPool
{
    private Dictionary<int, Stack<GameObject>> mObjs;

    public XObjectPool()
    {
        mObjs = new Dictionary<int, Stack<GameObject>>();
    }

    public void push(int type, GameObject instance)
    {
        if (!mObjs.ContainsKey(type))
            mObjs.Add(type, new Stack<GameObject>());
        mObjs[type].Push(instance);
        instance.SetActive(false);
    }

    public GameObject pop(int type, GameObject prefab)
    {
        if (!mObjs.ContainsKey(type))
            mObjs.Add(type, new Stack<GameObject>());

        if (mObjs[type].Count == 0)
        {
            return GameObject.Instantiate(prefab);
        }
        else
        {
            return mObjs[type].Pop();
        }
    }
}